﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
using INTEX.DataBase;
using INTEX.DataBase.Tools;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{

    public class JLTWVKDOCData : BaseFunction
    {
        public bool checkVK07 = true;
        SETINTEXDB INTEXDB = new SETINTEXDB();
        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }
        public string UserID
        {
            get
            {
                return app.User;
            }
        }
        public JLTWVKDOCData()
            : base()
        {

        }
     
        public DataSet GetData(string MANDANT, string KRS, string LFD)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();

            try
            {
                SResult = INTEXBL.QueryVKK(MANDANT, KRS, LFD);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ABPOS + ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("查询完成", StatusEventType.StopProgress);
            }
            return SReturn;
        }
        public string Today
        {
            get
            {
                DateTime now = System.DateTime.Now;
                string year = now.Year.ToString();
                string m =Right("00" +now.Month.ToString(),2);
                string day = Right("00" +now.Day.ToString(),2);
                return year + m + day;
            }
        }
        public DataSet LoadQPPLAN()
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
                        DataRow dwTemp;
            try
            {
                dwTemp = INTEXDB.QPPLAN.NewRow();
                dwTemp["QPPMANDANT"] = "00";
                SResult = INTEXDBC.QueryQPPLAN(dwTemp, 2);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;

        }
        public DataSet GetQPStep(string art,DataRow dwInput=null)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataRow dwTemp;
            DataRow dwQPZUORD;
            try
            {
                if (dwInput == null)
                {
                    dwTemp = INTEXDB.QPZUORD.NewRow();
                    dwTemp["QPZART"] = Left(art, 20);
                    dwTemp["QPZVAR"] = "   ";
                    SResult = INTEXDBC.QueryQPZUORD(dwTemp);
                    SReturn.Merge(SResult);
                    if (!SResult.Tables.Contains("QPZUORD"))
                    {
                        return SReturn;
                    }
                    if (SResult.Tables[0].Rows.Count == 0)
                        return SReturn;
                    dwQPZUORD = SResult.Tables[0].Rows[0];
                }
                else
                {
                    dwQPZUORD = dwInput;
                }
                /*
                dwTemp = INTEXDB.QPPLAN.NewRow();
                dwTemp["QPPPNRKRS"] = dwQPZUORD["QPZPNRKRS"];
                dwTemp["QPPPLFDNR"] = dwQPZUORD["QPZPLFDNR"];
                SResult = INTEXDBC.QueryQPPLAN(dwTemp);
                SReturn.Merge(SResult);
              */
                SResult = INTEXDBC.QueryQPSTEP(dwQPZUORD,2);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }   
        
        public override DataSet LogIn(string MANDANT, string UsingID, System.Security.SecureString sPassword)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult;
            DataTable tableLocal = null;
            OracleCommand or1;
            try
            {
                IntPtr p = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(sPassword);
                string Password = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p);
                UsingID = UsingID.Trim().ToUpper();
                Password = Password.Trim().ToUpper();
                DataRow dwTemp = INTEXDB.HRSTAMM.NewRow();
                dwTemp["HRMANDANT"] = MANDANT;
                dwTemp["HRBENID"] = Left(UsingID + "                    ", 8);
                dwTemp["HRDFAX"] =Left(Password+"                    ",20);
                SResult = INTEXDBC.QueryHRSTAMM(dwTemp, 1);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); ;
            }
            return SReturn;
        }
    }
}